Skip to content

Conversation

@NeoIsRecursive
Copy link
Contributor

@NeoIsRecursive NeoIsRecursive commented Oct 6, 2025

When doing ajax requests users (me atleast) probably expect to use the xsrf-cookie value to provide an X-Xsrf-token header.

The issue is that the cookie value is an encrypted version of the csrf uuid, so the comparison will always fail (uuid != encryptedUuid).

I had to do an urldecode on the header value when I tested it in an application, which is why it is there. Should this be done on the client instead?

EDIT: seems like axios does this on the client, so it might be something the client should handle.
Maybe using urlencoded base64 strings by default would be nice? I think webauthn stuff uses that to make it easier sending the data around.

I used laravel as a reference for this fix/change:
https://github.com/laravel/framework/blob/1f0bcbf0941923d7f884459a9f5fcfbd16bb8ac8/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php#L153

Would this be considered a breaking change?

@NeoIsRecursive NeoIsRecursive changed the title fix(http): csrf header validation fix(http): xsrf header validation Oct 6, 2025
@brendt brendt requested a review from innocenzi October 6, 2025 11:03
@NeoIsRecursive
Copy link
Contributor Author

NeoIsRecursive commented Oct 10, 2025

Hi @innocenzi , sorry for the ping but would appreciate a re-review when you've got the time. Thanks!
(sorry for being impatient, but inertia doesn't work unless you disable csrf atm 😅)

@innocenzi
Copy link
Member

@NeoIsRecursive sorry for the delay, does Axios/Inertia work with this PR?

@NeoIsRecursive
Copy link
Contributor Author

@innocenzi yes!

@innocenzi innocenzi merged commit d1ee721 into tempestphp:main Oct 11, 2025
79 checks passed
@innocenzi
Copy link
Member

I'll trust you then, haven't had time to test it but it does look like it would 👍

@NeoIsRecursive NeoIsRecursive deleted the fix/xsrf-header-from-cookie-not-working branch October 11, 2025 19:50
@NeoIsRecursive
Copy link
Contributor Author

I'll trust you then, haven't had time to test it but it does look like it would 👍

Heh, I did forget one thing and that was to test with the default cookie name (forgot I had changed that to match tempest), tempest has xsrf-token in lowercase while axios by default looks for the same but in uppercase.

I don't know if that is reason enough to change it to be uppercased?

Sorry for missing this... 🫣

@innocenzi
Copy link
Member

I'm fine uppercasing it, I thought cookie names were case insensitive though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants